// pages/message/message.js
const app = getApp();
let Api = require('../../api/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        listData: [],
        pageSize:30,
        pageIndex:0, 
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let self = this;
        self.loadMore();
    },
    //加载消息列表
    loadMore:function(){
        let self = this;
        self.setData({
            pageIndex: self.data.pageIndex + 1,
        })
        Api.get(app.globalData.mallDomain, { //23、展示消息列表
            doShowMessageList: 1,
            token: app.globalData.token,
            pagesize: self.data.pageSize,
            pageindex: self.data.pageIndex,
        }).then(res => {
            console.log(res)
            if (res.data.msg == '121') {
                res.data.list.forEach(ele => {
                    self.setData({
                        listData: self.data.listData.concat({
                            Tilte: ele.Tilte,
                            TContent: ele.TContent,
                            GetTime: self.getNewTime(ele.GetTime),
                            Status: ele.Status,
                        })
                    })
                })
            }
        })
    },
    // 得到新的日期格式
    getNewTime:function(val){
        let self= this;
        let newArray = val.split(' ');
        return newArray[0].replace(/\//g, '-');
    },
    //上拉加载
    pull: function (e) {
        let self = this;
        if (self.data.listData.length > 10){
            self.loadMore();
        }
    },

})